grammar BandLanguage;
@header{
    package com.language.parser;
}

//张三在喇叭帮区执行喇叭工具的发声部件
script: (stmt Dot?)+ ;

stmt: simpleStmt | complexStmt;

simpleStmt: runToolStmt|
            subject_predicate_object_stmt |
            subject_predicate_attribute_object_stmt |
            subject_adverbial_predicate_attribute_object_stmt |
            subject_adverbial_predicate_complement_attribute_object_stmt |
            judgeStmt|
            subject_predicate;


//运行工具语句为典型的即时型命令句
    //如 张三 在 喇叭 帮区 执行 喇叭 工具的 发声 部件，喇叭id为 1
    runToolStmt:Char+ At (Char+ Band|ThisBand) Run Char+ Tool_s Char+ Unit (Dot|(Comma paramStmt)+ Dot);
        //执行工具语句后半部分为参数语句，由若干个参数组成。

        paramStmt:(noun Is Char+ |Char+ Is Char+|noun Is Char+ noun) ;

//复杂句由 定时型语句 和 监听型语句 组成
complexStmt:  concurrentStmt|scheduleStmt | listenStmt|(adverbial Comma)? ifStmt ;
 //定时型语句，如每一天8点,张三 在 喇叭 帮区 执行 喇叭 工具的 发声 部件，喇叭id为 1
    scheduleStmt:timeAdverbial Comma stmt;
    //时间状语从句
        timeAdverbial:Every (Year?|Number Year)(Month?|Number Month)(Day?|Number Day)
        (Hour?|Number Hour)(Minute?|Number Minute)(Second?|Number Second);

    //监听型语句，如 当 监听到 消息总线 设备故障 类型 消息，帮区为喇叭帮区 ，则 张三 在 当前帮区 执行 消息板工具 ，消息版为XXX，消息为XXX，
    listenStmt:When Listen MessageBus Char+  Type Message (Comma paramStmt)+ Comma  Then triggerStmt;
    triggerStmt: simpleStmt | complexStmt;

subject_predicate_object_stmt: subject? predicate object;
subject_predicate_attribute_object_stmt: subject? predicate attribute object;
subject_adverbial_predicate_attribute_object_stmt: adverbial Comma subject? predicate attribute? object |
                                                   subject? adverbial predicate attribute? object;
subject_adverbial_predicate_complement_attribute_object_stmt: (adverbial Comma)? subject? predicate attribute? object complement|
                                                              subject? adverbial? predicate attribute? object complement;
subject_predicate: subject predicate;

ifStmt: If judgeStmt Comma Then simpleStmt;
concurrentStmt: simpleStmt Comma Concurrent simpleStmt;
judgeStmt: object comparator object | object isExist | object notExist |object predicate object | Char+ Is Char+;//
subject: Me | Char+;
predicate: verb;
object: object With object |
        object Of object |
        Number | String | Char+ |
        noun;
attribute: adjective | String | Char+ | noun;
adverbial: place_adverbial | preposition_object;
complement:  direction;//time_complement
place_adverbial: preposition object direction?;
preposition_object: place_adverbial? preposition attribute? object;
isExist: Exist;//
notExist: NotExist;//
//time_complement: Number Quantifier? TimeUnit;

comparator: MoreThan | LessThan | Equals;
logic_operator: And | Or;
noun: Organization | Department | SubDepartment | Band | Position | Role | Member | Tool | MaxAuthority | MinAuthority | Deadline | Reader |
      Writer | Speaker | Worker | Administrator | Drama | File | Chatroom | SuperiorDepartment | ParentDepartment | ParentBand | SubBand |
      Authority | NewStaff | SeniorStaff |Stranger;
verb: Establish | Join | Delete | Accept | Grant | Publish | Dispatch | SendMsg | Show | Edit | Disable | Enable | Appear | Have | Merge |
      Change | Set | Move | Revoke | CancelPub | Appoint | Alarm ;//
adjective: Incumbent | Leaved ;
preposition: At | Make | From;//
direction: Inside;


//金辉 在 喇叭 帮区 执行 喇叭 工具的 发声部件
Organization: '机构';
Department: '部门';
ParentDepartment: '父部门';
SuperiorDepartment: '上级部门';
SubDepartment: '子部门' | '下级部门';
Band: '帮区';
ParentBand: '父帮区';
SubBand: '子帮区';
Position: '岗位';
Member: '成员';
Tool: '工具';
Role: '角色';
Authority: '权限';
Reader: '读者';
Writer: '写者';
Speaker: '言者';
Worker: '工者';
Administrator: '管理员';
Drama: '剧本';
File: '文档';
Chatroom: '消息板';
MaxAuthority: '最高权限' | '最大权限';
MinAuthority: '最小权限' | '最低权限';
Deadline: '有效期' | '有效时长';
NewStaff: '新员工';
SeniorStaff: '老员工';

Stranger:'生人'|'陌生人';
Show: '显示' | '列出' | '查看';
Establish: '创建' | '新建' | '新增';
Join: '添加' | '加入' | '加入到' | '拉入' | '拉入到';
Revoke: '撤消' | '撤消掉';
Set: '设定';
Change: '更换' | '更换到';
Edit: '修改' | '修改为';
Delete: '移除' | '删除' | '剔除' | '去除' | '删掉';
Merge: '合并' | '合并为' | '合并到';
Move: '移动' | '移动到';
Appoint: '任命' | '安排';
Relieve: '免除';
Grant: '授予';
Disable: '停用';
Enable: '启用';
SendMsg: '发消息' | '通知';
Accept: '吸收' | '接纳';
Dispatch: '派遣到' | '分派到';
Publish: '发布' | '发布到' | '发布给';
CancelPub: '取消发布';
Exist: '存在';
NotExist: '不存在';
Appear: '出现' | '出现在' | '要出现在';
Have: '拥有' | '要拥有'| '有';
Alarm: '警报' | '报警';


Incumbent: '在职的';
Leaved: '离职的';

Me: '我';



At: '在' | '于';
Make: '把' | '将' | '对' | '给';//
From: '从';
Quantifier: '个' | '次' | '条';
//TimeUnit: '分钟' | '小时' | '天' | '月' | '年';
MoreThan: '大于' | '大于等于';
LessThan: '小于' | '小于等于';
Equals: '等于';
And: '且';
Or: '或';
Inside: '里' | '内' | '中';

With: '和';
Of: '的';

If: '如果' | '假如';
Then: '则' | '那么';
Concurrent: '同时' | '并';
Else: '否则';



Listen:'监听到';
Type: '类型';
Message: '消息';
Is:'为';
Every:'每';
When: '当';
Run:'执行';
Unit:'部件';
Tool_s:'工具的';
ThisBand:'当前帮区';
MessageBus:'消息总线';



Year:'年';
Month:'月';
Day:'日'|'天';
Hour:'时'|'点';
Minute:'分'|'分钟';
Second:'秒';

Comma: ',' | '，';
Dot :'.'|'。';
Number :[0-9]+;
String: '‘' (.)*? '’';

Char: ([a-zA-Z0-9$_] | [\u4E00-\u9FA5]);


//Identifier: ([a-zA-Z0-9$_] | [\u4E00-\u9FA5])+;
Ws :[ \t\r\n]+ -> skip;
Comment :'//' ~[\r\n]* -> channel(HIDDEN);





